package com.hua.designpattern.j2eepattern.filterinterceptor;

import java.util.ArrayList;
import java.util.List;

public class FilterChain {

	private int index = 0;
	private List<FilterInterface> filters = new ArrayList<FilterInterface>();

	public void doFilter(String request, String response) {
		if (index < filters.size()) {
			index++;
			filters.get(index - 1).doFilter(request, response, this);
		}
	}

	public FilterChain addFilter(FilterInterface filter) {
		this.filters.add(filter);
		return this;
	}

	public FilterChain init() {
		index = 0;
		return this;
	}

}
